from consql import dbCon,rootCon


def loginstudent(u):
    con=None
    try:
        con=dbCon.getCon()
        cur=con.cursor()
        sql='select * from student where name=%s and password=md5(%s)'
        cur.execute(sql,(u.username,u.password))
        con.commit()
        result=cur.fetchall()
        if len(result)==0:
            return False
        else:
            return True
    except Exception as e:
        print(e)
    #     con.rollback()
    #     return False
    # finally:
    #     dbCon.closeCon(con)

def loginroot(u):
    flag=True
    con=None
    try:
        con=rootCon.getCon(u)
    except Exception as e:
        print(e)
        flag=False
        return flag
    finally:
        rootCon.closeCon(con)
        return flag

